<?php
class PurviewModel extends Model {
	var $tableName = 'portal_purview';

	function isAllow($uid,$type,$channelId){
		$map['uid'] = $uid;
		if(!empty($tree)){
			$map['channelId'] = $channelId;
		}
		
		$one = $this->where($map)->find();
		if(!$one){
			return false;
		}
		
		$purview = unserialize($one['purview']);
		if(!isset($purview[$type]) || empty($purview[$type])){
			return false;
		}
		
		return true;
	}
	
	function addPurview($uid){
		$purview['manage'] = 1;
		$purview['page']   = 1;
		$purview['model']  = 1;
		$purview['cms']    = 1;
		
		$map['uid']     = $uid;
		$map['channelId']    = $_POST['channelId'];
		$map['purview'] = serialize($purview);
		
		return $this->add($map);
	}
	
	function eidtPurview(){
		$manage = $_POST['manage'];
		$page   = $_POST['page'];
		$model  = $_POST['model'];
		$cms    = $_POST['cms'];
	
		$ids   = $_POST['ids'];
		foreach ($ids as $id){
			$purview['manage'] = $manage[$id];
			$purview['page']   = $page[$id];
			$purview['model']  = $model[$id];
			$purview['cms']    = $cms[$id];

			$map['id']      = $id;
			$data['purview'] = serialize($purview);
			
			$res = $this->where($map)->save($data);
		}

		return $res;		
	}
}

?>